# import jieba
# #打开小说，读取内容，并进行分词
# txt=open("《西游记》.txt",'r',encodings='utf-8').read()
# #print分词
# #jieba分词
# words=jieba.lcut(txt)
# #5,添加排除词
# exclude={"一个","那里","怎么","我们","不知","两个","甚么","只见","不是","原来","不敢","闻言","如何","甚么",}
# words=jieba.lcut(txt)
# #print(words)
# #2.记数 统计词语出现的次数
# #{‘国王’：1，}
# counts={}
# #定义一个空字典，存放遍历到的次的出现次数
# for word in words:
#     #去掉字数为1的，及其标点符号
#     if len(word)==1:
#         continue
#     #合并人物不同的称呼：
#     elif word=='行者' or word=='大圣' or word=='老孙':
#         rword="悟空"
#     elif word=='师父' or word=='三藏' or word=='长老':
#         rword="唐僧"
#     elif word=='悟净' or word=='沙和尚':
#         rword="沙僧"
#     elif word=='悟能' or word=='猪八戒' :
#         rword="八戒"
#     else:
#         rword=word
#     #如果该次数不在字典中，添加新元素（第一次出现）
#     #如果在字典中，修改氧元素的value(前面统计过的)
#     if rword in counts:
#         counts[word]+=1
#     else:
#         counts[word]=1
# #print()
# #6,字典中删除词
# for word in exclude:
#     if word in counts:
# del counts[word]
# items=list(counts.items())
# items.sort(key=lambda x:x[1],reverse=True)
# print(items)
# for i in range(10):
#     word,counts=items[i]
#     print("{0:<5}:{1:>5}".format(word,counts)
